﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using WF.Common;
using Com.DAO;

namespace WF.Web
{
    public partial class Main : System.Web.UI.Page
    {
        public string mainFormName = "MainForm.aspx";
        private List<TabPages> tabPages;


        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                if (null != this.ViewState["TabPages"])
                {
                    tabPages = (List<TabPages>)this.ViewState["TabPages"];
                    int i = 2;
                    foreach (TabPages t in tabPages)
                    {
                        Literal tabTitle = new Literal();
                        tabTitle.Text = "<li id=\"1" + i + "\"><a href=\"#tabs-" + i + "\">" + t.Title + "</a><span class=\"ui-icon ui-icon-close\">Remove Tab</span></li>";
                        tabTitle.EnableViewState = true;
                        //this.tabsTitle.Controls.Add(tabTitle);


                        Literal tabPage = new Literal();
                        tabPage.Text = "<div id=\"tabs-" + i + "\"><iframe id=\"mainBody" + i + "\" name=\"mainBody" + i + "\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" src=\"" + t.Url + "\" onload=\"SetWinHeight(this);\" ></iframe></div>";
                        tabPage.EnableViewState = true;
                        //this.tabs.Controls.Add(tabPage);

                        i = i + 1;
                    }
                }
            }
            else
            {
                tabPages = new List<TabPages>();
                this.ViewState["TabPages"] = tabPages;
            }
            //WF.BusinessObject.SystemSetting sysSet = new BusinessObject.SystemSetting();
            //if (sysSet.GetValueByParamName("IsInWorkFlow") == "0")
            //{
            //mainFormName = "MainForm_nowf.aspx";
            //}
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            TabPages t = new TabPages();
            t.Title = "职员信息查看";
            t.Url = "tabs.html";

            tabPages.Add(t);

            int i = tabPages.Count + 1;

            this.ViewState["TabPages"] = tabPages;

            Literal tabTitle = new Literal();
            tabTitle.Text = "<li id=\"1" + i + "\"><a href=\"#tabs-" + i + "\">" + t.Title + "</a><span class=\"ui-icon ui-icon-close\">Remove Tab</span></li>";
            tabTitle.EnableViewState = true;
            //this.tabsTitle.Controls.Add(tabTitle);


            Literal tabPage = new Literal();
            tabPage.Text = "<div id=\"tabs-" + i + "\"><iframe id=\"mainBody" + i + "\" name=\"mainBody" + i + "\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" src=\"" + t.Url + "\" onload=\"SetWinHeight(this);\" ></iframe></div>";
            tabPage.EnableViewState = true;
            //this.tabs.Controls.Add(tabPage);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            tabPages.RemoveRange(0, tabPages.Count);
            List<Control> ls = new List<Control>();
            //foreach (Control o in this.tabsTitle.Controls)
            //{
            //    if (o.GetType() == typeof(Literal))
            //    {
            //        ls.Add(o);
            //    }
            //}
            //foreach (Control o in ls)
            //{
            //    this.tabsTitle.Controls.Remove(o);
            //}

            //ls = new List<Control>();

            //foreach (Control o in this.tabs.Controls)
            //{
            //    if (o.GetType() == typeof(Literal))
            //    {
            //        ls.Add(o);
            //    }
            //}
            //foreach (Control o in ls)
            //{
            //    this.tabs.Controls.Remove(o);
            //}
        }



    }


    [Serializable]
    public class TabPages
    {
        private string title;

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private string url;

        public string Url
        {
            get { return url; }
            set { url = value; }
        }
    }
}